package com.itany.corejava.code07_面向对象.bms;

/**
 * @author: 石小俊
 * @date: 2023年03月09日 17:11
 * @version: 1.0
 */
public class LoanCreditAccount extends CreditAccount implements Loanable {

    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void provideLoan(double money) {
        // 当前贷款总额 = 原有的贷款总额+当前贷款的金额
        loanAmount += money;
    }

    @Override
    public boolean payLoan(double money) {
        // 当账户余额+透支额度 >= 还贷的金额,还贷才能成功
        if (getBalance() + getLimit() >= money) {
            // 还贷后金额减少
            setBalance(getBalance() - money);
            // 贷款总额减少
            loanAmount -= money;
            return true;
        }
        return false;
    }

    @Override
    public double queryLoan() {
        return this.loanAmount;
    }
}
